package com.liz.springCloudAlibaba.consumer;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.liz.springCloudAlibaba.consumer.service.ProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class DemoController extends ParentController {
    @Value("${server.port}")
    String port;
    @Value("${spring.application.name}")
    String applicationName;

    @Value("${testKey:nacos不配置时的默认值}")
    private String testKey;

    @Autowired
    ProviderClient providerClient;

    /**
     * SpringCloud Alibaba微服务实战(五) - Sentinel实现限流熔断
     * https://blog.csdn.net/u012081441/article/details/109246851
     *
     * @return
     */
    @GetMapping("/sentinelDemo")
    @SentinelResource(value = "/sentinelDemo",
            blockHandler = "blockHandler111", blockHandlerClass = {ParentController.class},
            fallback = "fallback111", fallbackClass = {ParentController.class}
    )
    public String getInfo() {
        System.out.println("testKey=" + testKey);
        String result = providerClient.getInfo();
        result += " , (来自配置中心的配置)testKey= " + testKey;
        return result;
    }


    @GetMapping("liveness")
    public String liveness() {
        return "{\"data\":\"alive\"}";
    }

}
